#include"head.h"

int to_work(int net_fd){

    bool login_stat = false;

    while(1){

        int instruction = -1;

        int recv_byte = recv(net_fd, &instruction, sizeof(instruction), 0);
        if(recv_byte == 0){
            printf("对方连接已断开\n");
            return 0;
        }

        if(!login_stat){

            if(instruction == LOGIN){

                login_stat = validate_login(net_fd);
                if(login_stat) printf("登陆成功\n");
            }

            if(instruction == REGIST){

                regsiter(net_fd);
            }
        }


        if(login_stat){

            switch(instruction){
            case RM:
                printf("Instruction: RM\n");
                break;
            case LS:
                printf("Instruction: LS\n");
                break;
            case PUTS:
                printf("Instruction: PUTS\n");
                break;
            case MKDIR:
                printf("Instruction: MKDIR\n");
                mkdirServe(net_fd);
                break;
            case GETS:
                printf("Instruction: GETS\n");
                break;
            case CD:
                printf("Instruction: CD\n");
                cdServe(net_fd);
                break;
            }

        }

    }

    return 0;
}
